//
//  FKImageTextChildVC.m
//  HappyTest
//
//  Created by Macbook Pro on 2019/2/15.
//  Copyright © 2019 Macbook Pro. All rights reserved.
//

#import "FKImageTextChildVC.h"
#import "FKImageTextCell.h"
#import "FKCommodityDetailVC.h"
static NSString *const TopId = @"FKImageTextCell";

@interface FKImageTextChildVC ()<FKImageTextCellDelegate, UIWebViewDelegate>

@property (nonatomic, strong) NSArray *datas;
@property (nonatomic, assign) CGFloat webCellH;

@property (nonatomic, strong) UIWebView *webView;

@end

@implementation FKImageTextChildVC

- (NSArray *)datas
{
    if (!_datas) {
        _datas = [NSArray array];
    }
    return _datas;
}

- (void)setUrl:(NSString *)url
{
    _url = url;
    
    [self.webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:url]]];
}

- (void)viewDidLoad {
    [super viewDidLoad];

    CGFloat webH = fkScreenH - fkStatusAndNaBarH - fk_adjustW(45) - fk_adjustW(50);
    UIWebView *webView= [[UIWebView alloc] initWithFrame:CGRectMake(0, 0, fkScreenW, webH)];
    [self.view addSubview:webView];
    self.webView = webView;
    webView.delegate = self;
    webView.scalesPageToFit = true;
    self.tableView.tableHeaderView = webView;
}

- (void)dealloc
{
    NSLog(@"%s", __func__);
}

#pragma mark - UIWebViewDelegate
- (void)webViewDidFinishLoad:(UIWebView *)webView
{
    NSString *path = [[NSBundle mainBundle] pathForResource:@"ImageText.js" ofType:nil];
    NSData *data = [NSData dataWithContentsOfFile:path];
    NSString *jsStr = [data mj_JSONString];
    // 执行js去除图片之间的间距
    [webView stringByEvaluatingJavaScriptFromString:jsStr];
    
    CGFloat webviewH = [[webView stringByEvaluatingJavaScriptFromString:@"document.body.scrollHeight"] floatValue];
    self.webView.fk_height = webviewH;
    self.tableView.tableHeaderView = self.webView;
    
    NSLog(@"---(%f)---", webviewH);
}


@end
